<?php

namespace Biz\model\advertisement;


class MPositionExtend extends MBaseDbModel
{
    const _CONFIG_FILE_ = 'db_position';

    const _CONFIG_SELECT_ = 'db_position';

    const _DATABASE_ = 'hhz_position';

    const _TABLE_NAME = 'hhz_position_extend';

    /**
     * 列表扩展信息的取值,资源位配置id=>记录
     * @param $ids
     * @return array|bool
     */
    public static function fetchExtListByIds($ids)
    {
        $list = empty($ids) ? [] : self::select('*', ['base_id' => $ids]);

        return empty($list) ? [] : array_column($list, null, 'base_id');
    }

    /**
     * 列表扩展信息的取值,资源位配置id=>记录
     * @param $id
     * @return array|bool
     */
    public static function fetchInfoById($id)
    {
        return empty($id) ? [] : self::get('*', ['base_id' => $id]);
    }

    /**
     * 自定义弹窗
     * @param $baseInfoId
     * @param $title
     * @param $sign
     */
    public static function saveCustomPopups($baseInfoId, $title, $sign)
    {
        if ($id = self::get('id', ['base_id' => $baseInfoId])) {
            self::update(['title' => $title, 'sign' => $sign], ['id' => $id]);
        } else {
            self::insert(['base_id' => $baseInfoId, 'title' => $title, 'sign' => $sign]);
        }
    }

    /**
     * tab4 运营位
     * @param $baseInfoId
     * @param $title
     * @param $keyWord
     */
    public static function saveOperationPos($baseInfoId, $title, $keyWord)
    {
        if ($id = self::get('id', ['base_id' => $baseInfoId])) {
            self::update(['title' => $title, 'key_word' => $keyWord], ['id' => $id]);
        } else {
            self::insert(['base_id' => $baseInfoId, 'title' => $title, 'key_word' => $keyWord]);
        }
    }

    /**
     * tab4 好物推荐线卡片
     * @param $baseInfoId
     * @param $objId
     * @param $objType
     */
    public static function saveTab4Card($baseInfoId, $objId, $objType)
    {
        if ($id = self::get('id', ['base_id' => $baseInfoId])) {
            self::update(['obj_id' => $objId, 'obj_type' => $objType], ['id' => $id]);
        } else {
            self::insert(['base_id' => $baseInfoId, 'obj_id' => $objId, 'obj_type' => $objType]);
        }
    }

    /**
     * 底部导航tips
     * @param $baseInfoId
     * @param $index
     */
    public static function saveAppNavIcon($baseInfoId, $index)
    {
        if ($id = self::get('id', ['base_id' => $baseInfoId])) {
            self::update(['pos' => $index], ['id' => $id]);
        } else {
            self::insert(['base_id' => $baseInfoId, 'pos' => $index]);
        }
    }

    /**
     * 存储搜索结果页topBanner的搜索词
     * @param $baseInfoId
     * @param $key_word
     */
    public static function saveSearchResultBanner($baseInfoId, $key_word)
    {
        if ($id = self::get('id', ['base_id' => $baseInfoId])) {
            self::update(['key_word' => $key_word], ['id' => $id]);
        } else {
            self::insert(['base_id' => $baseInfoId, 'key_word' => $key_word]);
        }
    }

    /**
     * 存储设计师个人主页banner的设计师uid
     * @param $baseInfoId
     * @param $uid
     */
    public static function saveDesignerHomeBanner($baseInfoId, $uid)
    {
        if ($id = self::get('id', ['base_id' => $baseInfoId])) {
            self::update(['uid' => $uid], ['id' => $id]);
        } else {
            self::insert(['base_id' => $baseInfoId, 'uid' => $uid]);
        }
    }

    /**
     * 存储设计师个人主页banner的设计师uid
     * @param $baseInfoId
     * @param $sign
     * @param $key_word
     */
    public static function saveSearchSuggestRank($baseInfoId, $sign, $key_word)
    {
        if ($id = self::get('id', ['base_id' => $baseInfoId])) {
            self::update(['sign' => $sign, 'key_word' => $key_word], ['id' => $id]);
        } else {
            self::insert(['base_id' => $baseInfoId, 'sign' => $sign, 'key_word' => $key_word]);
        }
    }
}

